package com.zd.controller;


import com.github.pagehelper.PageInfo;
import com.sun.xml.internal.rngom.parse.host.Base;
import com.zd.model.UserInfo;
import com.zd.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/userInfo")
public class UserInfoController extends BaseController {

    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 用户信息查询
     * @return
     */
    @GetMapping("/queryUserInfo")
    public String queryUserInfo(@RequestParam(name = "pageNum", required = false, defaultValue = "1")
                                        int pageNum,
                                @RequestParam(name = "pageSize", required = false, defaultValue = "10")
                                        int pageSize, UserInfo queryInfo, Model model){

        List<UserInfo> userInfoList = userInfoService.selectByPrimaryKey(pageNum, pageSize, queryInfo);

        model.addAttribute("pageInfo",new PageInfo<>(userInfoList));
        model.addAttribute("userInfoList",userInfoList);


        return "userInfoIndex";
    }

    /**
     * 跳转用户添加页面
     * @return
     */
    @GetMapping("/toUserInfoAdd")
    public String toUserInfoAdd(){

        return "userInfoAdd";
    }


    /**
     * 用户信息添加
     * @param userInfo
     * @return
     */
    @ResponseBody
    @PostMapping("userInfoAdd")
    public boolean userInfoAdd(UserInfo userInfo){

        userInfoService.insertUserInfo(userInfo);

        return true;
    }

    /**
     * 跳转重置密码页
     * @param id
     * @return
     */
    @GetMapping("toResetPassword")
    public String toResetPassword(int id,Model model){

        model.addAttribute("id",id);
        return "userInfoUpdate";
    }

    /**
     * 重置密码方法
     * @param userInfo
     * @return
     */
    @ResponseBody
    @PostMapping("resetPassword")
    public boolean resetPassword(UserInfo userInfo){

        userInfoService.resetPassword(userInfo);

        return true;
    }


    /**
     * 逻辑删除用户信息
     * @param id
     * @return
     */
    @ResponseBody
    @GetMapping("deleteUserInfo")
    public boolean deleteUserInfo(int id){

        userInfoService.deleteUserInfo(id);

        return true;
    }


}
